<?php
include 'TaksasiDAO.classes.php';
class TaksasiCalculator{
	private $tree_composition; // komposisi tanaman TM
	
	private $BJR; // berat  janjang rata2
	private $BPH; // berat total (ton) per hektar / tahun 
	private $nPerHa = 136; // n tanaman per ha
	
	public function TaksasiCalculator(){
        $bjr = new BjrDAO(); 
        $this->BJR = $bjr->get();

        $bph = new BphDAO(); 
        $this->BPH = $bph->get();

        $composition = new TreeCompositionDAO(); 
        $this->tree_composition = $composition->get();
	}	 
	
	public function calculate(){
        if( $this->BJR == null || 
            $this->BPH == null ||
            $this->nPerHa < 1 ){
            
            return NULL;
        }
        
		$janjang = array();
		foreach($this->tree_composition as $tm=>$nTanaman){
		
			// yield
			$yield = ($nTanaman / $this->nPerHa) * $this->BPH[$tm]; // ton/tahun

			$janjang[$tm] = round(($yield*1000)/ $this->BJR[$tm]);
		}
		
		return $janjang;
	}
	
	public function setComposition($comp){
		$this->tree_composition = $comp;
	}
	
	public function setBJR($bjr){
		$this->BJR = $bjr;
	}
	
	public function setBPH($bph){
		$this->BPH = $bph;
	}
}
?>